package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns ="/getannouncement")
public class aninsertServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        announcementServiceImpl service = new announcementServiceImpl();
        String announcement_title = req.getParameter("title");
        String content = req.getParameter("content");
        String time = null;
        PrintWriter out =resp.getWriter();
        service.insert(announcement_title,content,time);
        /*req.setAttribute("title",announcement_title);*/
        resp.sendRedirect(req.getContextPath() + "success_insert.jsp");
        /*req.getRequestDispatcher("/delete_announcement.jsp").forward(req,resp);*/
        /*resp.sendRedirect(req.getContextPath() + "/delete_announcement.jsp");*/
    }
}
